<template>
	<view class="edit">
		<u-navbar  title="" back-text="个人中心" :is-back="true"  :background="{ background: '#000' }" :back-text-style="{color:'#FFF'}" back-icon-color="#fff"> </u-navbar>
		<div class="colCenter">
			<uploader class="cycle"   :file="form.avatar" pathFlag="3" tag="avatar" />
			<div class="tip"> 点击更换头像 </div>
		</div>

		<u-form :model="form" ref="uForm" label-width ="90px" :label-style="{'font-weight':600}">
			<div class="form-group">
				<u-form-item label="姓名"> <u-input v-model="form.realname" placeholder="请输入姓名"/> </u-form-item>
				<u-form-item label="性别" >  <div  @click="show = true"> {{ form.sex?'女':'男'}} </div></u-form-item>
				<u-form-item label="出生年月"> <u-input v-model="form.birthday" type="select"  @click="showDate = true" /></u-form-item>
				<u-form-item label="所在地"> <u-input v-model="form.address" placeholder="请输入所在地"/> </u-form-item> 
				<u-form-item label="公司名称"> <u-input v-model="form.companyName" placeholder="请输入公司名称"/> </u-form-item> 
				<u-form-item label="公司地址"> <u-input v-model="form.companyAddress" placeholder="请输入公司地址"/> </u-form-item> 
				<u-form-item label="手机号"> <u-input v-model="form.mobile" placeholder="请输入手机号"/> </u-form-item> 
				<u-form-item label="座右铭"> <u-input v-model="form.motto" placeholder="请输入座右铭"/> </u-form-item> 
			</div>
			<div class="form-group">
				<u-form-item label="实名认证"> 
				  <div class="flex">
					  <uploader :file="form.autonymPath1"  pathFlag="3" tag="autonymPath1"/>
					  <uploader :file="form.autonymPath2"  pathFlag="3" tag="autonymPath2"/>
				  </div>
				</u-form-item>
				<div class="flex">
					<div class="f-title">身份证号</div> <u-input v-model="form.idcard" placeholder=""/>
				</div>
				
			</div>	
			<div class="form-group">
				<u-form-item label="执业经纪认证">
				  <div class="flex">
				  	  <uploader :file="form.brokerPath"  pathFlag="3" tag="brokerPath"/>
				  </div>
				</u-form-item>
				<div class="flex">
					<div class="f-title">执业证号</div> <u-input v-model="form.idcard" placeholder=""/>
				</div>
				<u-form-item label="公司认证">
				  <div class="flex">
					  <uploader  :file="form.companyPath"  pathFlag="3" tag="companyPath" />
				  </div>
				</u-form-item>
				<view class="tip-infos cc"> 备注:以上认证将在提交后24小时内审核完成。 </view>
				
			  <view class="center"> <view class="btn u-btn" @click="submit"> 完成提交 </view> </view>
			</div>
		</u-form>
		
		 
		<u-action-sheet :list="actionSheetList" v-model="show" @click="actionSheetCallback"></u-action-sheet>
		<u-picker v-model="showDate" mode="time" @confirm="confirm"></u-picker>
		<tabBar/>
	</view>
</template>

<style lang="scss">
	.edit {
		.cycle{
			border-radius: 50%;
			 border:2px solid #FCCD04;
			 overflow: hidden;
			 margin-top: 10px;
		}
		.colCenter,.form-group{
			border-bottom: 10px solid #EEE;
			padding-bottom: 10px;
		}
		.form-group{
			padding: 0 30px 10PX 30PX;
		}
		.tip-infos{
		   font-size: 12PX;
		   margin:20px 0; 
		}
		.u-btn{
			margin: 20PX 0;
		}
	}
</style>

<script>
	export default {
		name: "price",
		data() {
			return {
				show:false,
				showDate:false,
				form: {name: '',intro: '',sex: '',gender: false,},
				actionSheetList: [ { text: '男',vaue:0,}, { text: '女',vaue:1,},], 
			};
		},
		created() {
			this.load()
		},
	methods: {
				confirm(data){
					console.log(data);
					this.form.birthday = `${data.year}-${data.month}-${data.day}`
					this.form.birthday1 = `${data.year}-${data.month}-${data.day} 00:00:00`
				},
				actionSheetCallback(index) {
					this.form.gender = this.actionSheetList[index].text;
					this.form.sex = this.actionSheetList[index].vaue;
				},
				async load() {
				   var tmp = this.$store.state.apiUserInfo
				   
				   if (!tmp.userId) { 
				   	var res = await this.ajax('/wx/user/getInfo')
				   	tmp = res.data;
				   	this.$store.dispatch("asyncApiUserInfo", res.data);
				   }
					this.form = tmp
					console.log("form",this.form);
					
					console.log("realname",this.form.realname);
					this.form.sex = this.form.gender =='女'?true:false,
					this.form.autonymPath1 = this.form.autonymPath.split(",")[0]
					this.form.autonymPath2 = this.form.autonymPath.split(",")[1]
					this.form.birthday = this.form.birthday.split(" ")[0]
				},
				async submit() {
					 
				      var tmp = this.$store.state.tmp
				       console.log(tmp);
				       var { avatar,autonymPath1,autonymPath2,brokerPath,companyPath} = tmp;
				       var autonymPath = autonymPath1 + "," + autonymPath2
				       console.log( this.form );
				       this.form.gender = this.form.sex ? 1 :0;// 1 女性
				       this.ajax('/wx/user/updateUser', Object.assign(this.form,{
				       autonymPath,brokerPath,companyPath,avatar,
				       nikename:this.form.realname,
					   birthday:this.form.birthday1,
				       status:0, 
				     }),'post').then((res)=>{
				       console.log(res);  
				     }); 
				},
			}
	}
</script>
